package com.hymns;

import com.hymns.domain.Hymn;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.content.*;

public class HymnsActivity extends Activity {
	GridView _myGrid;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		try {
			
			super.onCreate(savedInstanceState);

			setContentView(R.layout.main);

			_myGrid = (GridView) findViewById(R.id.mainGrid);

			_myGrid.setAdapter(new XmlAdapter(this));

			_myGrid.setOnItemClickListener(onItemClickListener);
			
		} catch (Exception e) {
			Log.e(this.toString(), e.getMessage() + e.getStackTrace());
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main_menu, menu);
		return true;
	}

	private OnItemClickListener onItemClickListener = new OnItemClickListener() {
		public void onItemClick(AdapterView<?> parent, View v, int position,
				long id) {
			Intent intent = new Intent(HymnsActivity.this, HymnActivity.class);

			Hymn hymn = (Hymn) v.getTag();

			String fileName = getResources().getString(R.string.fileName);

			intent.putExtra(fileName, hymn.get_File());

			startActivity(intent);
		}
	};
}